package com.tiancheng.trade.payment.enums;

import com.tiancheng.trade.commom.core.enums.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * @Author: likailun
 * @Description: 银联请求类型枚举
 * @Date: create in 2021/8/30 3:20 下午
 */
@Getter
@AllArgsConstructor
public enum UmsReqTypeEnum implements BaseEnum<String> {

    C2B_GET_QR("0210000903", "C2B 码申请"),
    C2B_GET_QR_BATCH("0260000903", "C2B 码批量申请"),
    C2B_ADDN_RECEIVE("0230000903", "C2B 附加处理"),
    C2B_ADDN_RECEIVE_NOTIFY("0240000903", "C2B 附加处理结果通知"),
    C2B_TRADE_NOTIFY("0250000903", "C2B 交易通知"),

    C2B_CONSUMER("0310000903","消费交易"),
    C2B_CONSUMER_RIGHTING("0320000903","消费冲正交易"),
    C2B_CONSUMER_REVOKE("0330000903","消费撤销交易"),
    C2B_CONSUMER_REFUND("0340000903","退货交易");

    private String code;
    private String desc;

    public static String getDesc(String code) {
        Optional<UmsReqTypeEnum> found = Arrays.stream(UmsReqTypeEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        if (found.isPresent()) {
            return found.get().getDesc();
        }
        return "";
    }

    public static UmsReqTypeEnum getByCode(String code){
        Optional<UmsReqTypeEnum> found = Arrays.stream(UmsReqTypeEnum.values()).filter(c -> c.code.equals(code)).findFirst();
        return found.orElse(null);
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }
}
